package top.datacluster.basic.algorithm.leetcode.dynamic;

public class LeetCode303 {

    private int[] dp;

    public LeetCode303(int[] nums) {
        this.dp = new int[nums.length];
        if (nums.length != 0){
            this.dp[0] = nums[0];
            for (int i = 1; i < nums.length; i++){
                this.dp[i] = this.dp[i - 1] + nums[i];
            }
        }

    }

    public int sumRange(int i, int j) {
        return i == 0 ?  dp[j] : (dp[j] - dp[i - 1]);

    }
}
